package com.gzu.ltms.controller.order;

import com.gzu.ltms.entity.OrderDetail;
import com.gzu.ltms.entity.dto.OrderDTO;
import com.gzu.ltms.response.Response;
import com.gzu.ltms.service.OrderDetailService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@Tag(name = "订单相关接口")
@Slf4j
public class OrderController {

    @Resource
    private OrderDetailService orderDetailService;


    /**
     * 创建订单
     *
     * @param orderDTO
     * @return
     */
    @PostMapping("/add")
    public Response<?> createOrder(@Validated @RequestBody OrderDTO orderDTO) {
        return orderDetailService.createOrder(orderDTO);
    }


    /**
     * 获取所有订单
     *
     * @return
     */
    @GetMapping("/get")
    public Response<List<OrderDetail>> getAllOrder() {
        return orderDetailService.getAllOrder();
    }

    /**
     * 根据id获取订单
     *
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public Response<OrderDetail> getOrderById(@PathVariable("id") Long id) {
        return orderDetailService.getOrderById(id);
    }

    /**
     * 删除订单
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public Response<?> delete(@RequestParam("id") Long id) {
        orderDetailService.removeById(id);
        return Response.success();
    }

}
